if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SaveCertificationContent]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[SaveCertificationContent]
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
/***************************************************************************
* Name:				SaveCertificationContent

* Purpose:			This Stored Procedure gets called On authentication(workflow step) and 
				saves the certification content to the database.The saved content will be 
				used to create the pdf on acceptance(by clicking the accept button in 
				workflow step after authentication)  

* PARAMETERS
* Name				Description					
* -------------			-----------------------------------------------------------
* @executionId int,		ExecutionId with respect to WorkFlow
* @fwkDomainUserId int,		FrameworkDomainUserId of the user accepting the 
				participation through workflow
* @activityName varchar(200)	WorkFlow Activity name (work flow which initiated the procedure)  
* @content ntext,		Serialized xml content to be used for PDF creation
* @serverMapPath  varchar(500)	Server path for the XSL liscence file
*
***************************************************************************/

CREATE Procedure dbo.[SaveCertificationContent]  
(  
@executionId int,  
@fwkDomainUserId int,  
@activityName varchar(200),  
@content ntext,
@serverMapPath  varchar(500)
)  
As   
BEGIN  
 If Not exists (Select Top 1 Id from WorkFlow_certified_content   
    where   
     ExecutionId=@executionId and  
     fwkDomainUserId = @fwkDomainUserId and   
     ActivityName = @activityName)  
 Begin  
  Insert into WorkFlow_certified_content  
    (ExecutionId,fwkDomainUserId,DateCreated,ActivityName,SerializedContent,ServerMapPath)   
  values  (@executionId,@fwkDomainUserId,GetDate(),@activityName,@content,@serverMapPath)  
 End  
Else
 BEGIN
	Update WorkFlow_certified_content  set DateCreated=GetDate(),SerializedContent=@content
 END        
END
